from apps.common.base_model import BaseModel
from exts import db


class Goods(BaseModel):
    __tablename__ = 't_goods'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50), default='', server_default='', comment='商品名称')
    category_id = db.Column(db.Integer, db.ForeignKey('t_goods_category.cat_id', ondelete='SET NULL', onupdate='CASCADE'), comment='商品分类id')
    market_price = db.Column(db.DECIMAL(12, 2), comment='市场价')
    price = db.Column(db.DECIMAL(12, 2), comment='实际价格')
    unit = db.Column(db.String(10), comment='计量单位', nullable=True)
    click_num = db.Column(db.Integer, default=0,server_default='0', comment='点击数')
    amount = db.Column(db.Integer, default=0,server_default='0', comment='销售量')
    stock_num = db.Column(db.Integer, default=0,server_default='0', comment='库存数量')
    fav_num = db.Column(db.Integer, default=0,server_default='0', comment='收藏数')
    status = db.Column(db.Integer, default=1, server_default='1', comment='商品状态')
    main_img = db.Column(db.String(100), comment='商品主图')
    is_recommend = db.Column(db.Boolean, default=False, server_default='0', comment='是否推荐')
    goods_desc = db.Column(db.Text, comment='商品详情')

    def __repr__(self):
        return self.name
